package com.fs.open.web;

import com.fs.common.utils.BaseConstants;
import com.fs.sys.bean.dto.DeptDTO;
import com.fs.sys.entityservice.DeptEntityService;
import jakarta.annotation.security.PermitAll;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 机构开放接口
 *
 * @author  LiuQi 2025/9/30-9:41
 * @version V1.0
 **/
@RestController
@RequestMapping("/open/dept")
@PermitAll
public class OpenDeptController {
    @Autowired
    private DeptEntityService deptEntityService;

    /**
     * 查询所有机构列表
     * @return 机构列表
     */
    @GetMapping("list")
    public List<DeptDTO> getAllDepts() {
        return deptEntityService.queryBuilder()
                .eq("tenant_id", BaseConstants.SUPER_TENANT)
                .eq("deleted", 0)
                .query();
    }

    @GetMapping("detail/{id}")
    public DeptDTO getDetail(@PathVariable("id") String id) {
        return deptEntityService.findById(id)
                .orElse(null);
    }
}
